;define(function (require) {
	'use strict';
	var $=require('jquery'),
		layer=require('layer');
		require('slide');
		require('touchSlide');
		require('slimscroll');
		require('fullpage');
	
	function app(){}
	app.prototype={
		init:function(){
			layer.load(1);
			var that = this;
			this.pageSize = this.getPageSize();
			
			/*轮播*/
			jQuery(".lunbo").slide({
				mainCell:".bd",
				autoPlay:true
			});
			
			$('.content').fullpage({
				resize:true,
				scrollOverflow:true,
				afterRender:function(){
					setTimeout(function(){
					  layer.closeAll('loading');
					}, 200);
					$('.fp-table.active').find('[anim]').each(function(i,e){
						that.addAnimate({
							obj:$(e),
							dtime:(i+1)*0.5
						});
					})
				},
				onLeave:function(index){
					/*var $obj = $('.fp-table').eq(index-1).find('[anim]');
					$obj.each(function(){
						$(this).removeAttr("style").removeClass('animated');
						$(this).addClass('hidden');
					})*/
				},
				afterLoad:function(){
					$('.fp-table.active').find('[anim]').each(function(i,e){
						if($(e).hasClass('animated')) return;
						that.addAnimate({
							obj:$(e),
							dtime:(i+1)*0.5
						});
					})
				}
			});
		}
		
		//动画生成
		,addAnimate:function(params){
			var that = this,
			 	$obj = params.obj,
			 	po = eval('('+$obj.attr('anim')+')'),
				zidx = po.zidx,                         //z-index
				name = po.name,                         //animation-name
				delay = po.delay,                       //animation-delay
				duration = po.duration,                 //animation-duration
				fun = po.fun?po.fun:'linear',       //animation-timing-function
				count = po.count?po.count:1,        //animation-iteration-count
				fill = po.fill?po.fill:'';       //fill-mode       
			//使用循序时间
			delay = params.dtime;
			//使用随机效果
			var animate_styles = ['bounceIn',
			'bounceInLeft','bounceInRight','fadeIn','fadeInLeft',
			'fadeInLeftBig','fadeInRight','fadeInRightBig','lightSpeedIn',
			'rollIn','zoomIn','zoomInDown','zoomInLeft','zoomInRight'];
			var as_len = animate_styles.length;
			function GetRandomNum(Min,Max){
				var Range = Max - Min;
				var Rand = Math.random();
				return(Min + Math.round(Rand * Range));
			}
			var aidx = GetRandomNum(0,as_len-1);
			var ardxg = animate_styles[aidx];
			//随机效果end
			
			//取出原先style
			var _styles = $obj.attr("append-style");
			if(_styles){
				_styles = $obj.clone().attr("append-style");
			}else{
				_styles = '';
			}
			if(($obj.attr('stop') && $obj.attr('stop')=="false") || (typeof $obj.attr('stop') == 'undefined')){
				$obj.removeAttr("style").removeClass('animated hidden');
				$obj.find('*').removeClass('hidden');
				//重新动画
				//setTimeout(function(){
					$obj.stop(true,false).addClass('animated').attr('style',
					//'visibility:visible;animation-name:'+name+';-webkit-animation-name:'+name
					'visibility:visible;animation-name:'+ardxg+';-webkit-animation-name:'+ardxg
					+';animation-delay:'+delay+';-webkit-animation-delay:'+delay
					+'s;animation-duration:'+duration+'s;-webkit-animation-duration:'+duration+'s;z-index:'+zidx
					+';animation-timing-function:'+fun+';-webkit-animation-timing-function:'+fun
					+';animation-iteration-count:'+count+';-webkit-animation-iteration-count:'+count
					+';animation-fill-mode:'+fill+';-webkit-animation-fill-mode:'+fill+';'+_styles);
				//}, 10);
			}else{
				$obj.stop(true,false).attr("stop",false);
			}
			return delay+duration;
		}
		
		,getPageSize:function(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight}}var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth}else{windowWidth=self.innerWidth}windowHeight=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight}else{if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight}}}if(yScroll<windowHeight){var pageHeight=windowHeight}else{var pageHeight=yScroll}if(xScroll<windowWidth){var pageWidth=xScroll}else{var pageWidth=windowWidth}var arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize}
	}
	return app;
})

